{% extends "zato/index.html" %}

{% block html_title %}Pub/sub delivery tasks{% endblock %}

{% block "extra_css" %}
    <link rel="stylesheet" type="text/css" href="/static/css/jquery.alerts.css">
{% endblock %}

{% block "extra_js" %}

    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.tablesorter.min.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.cookie.js"></script>
    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/jquery/jquery.alerts.min.js"></script>

    <script nonce="{{ CSP_NONCE }}" type="text/javascript" src="/static/js/common.js"></script>

    <script nonce="{{ CSP_NONCE }}">
    $.fn.zato.data_table.get_columns = function() {
        return [
            '_numbering',
            '_selection',

            'sub_key',
            '_topic',

            '_len_messages_history',
            'thread_id',

            '_last_sync',
            'last_iter_run',

            'server_name',
            'server_pid',

            'topic_id',
            'topic_name',

            '_clear',
            '_toggle',

            'last_sync',
            'last_sync_sk',

        ]
    }
    </script>

{% endblock %}

{% block "content" %}
<h2 class="zato">Pub/sub delivery tasks for {{ server_name }}:{{ server_pid }}</h2>

{% if not zato_clusters %}
    {% include "zato/no-clusters.html" %}
{% else %}

    <div id="user-message-div" style='display:none'><pre id="user-message" class="user-message"></pre></div>

    {% if cluster_id %}

        <div id="markup">
            <table id="data-table">
                <thead>
                    <tr class='ignore'>
                        <th style="max-width:1%">&nbsp;</th>
                        <th>&nbsp;</th>

                        <th><a href="#">Sub key</a></th>
                        <th><a href="#">Topic</a></th>

                        <th><a href="#">Messages</a></th>
                        <th><a href="#">Python</a></th>

                        <th><a href="#">Last sync</a></th>
                        <th><a href="#">Last iter run</a></th>

                        <th>&nbsp;</th>
                        <th>&nbsp;</th>

                        <th class='ignore'>&nbsp;</th>
                        <th class='ignore'>&nbsp;</th>

                </thead>

                <tbody>
                {% if items %}
                {% for item in items %}
                    <tr class="{% cycle 'odd' 'even' %}" id='tr_{{ item.id }}'>
                        <td class='numbering'>&nbsp;</td>
                        <td class="impexp"><input type="checkbox" /></td>

                        <td>

                        <a href="{% url "pubsub-endpoint-queues" cluster_id item.endpoint_id item.endpoint_name|slugify %}?cluster={{ cluster_id }}&amp;query={{ item.sub_key }}">{{ item.sub_key }}</a>
                        </td>

                        <td>
                            <a href="{% url "pubsub-topic" %}?cluster={{ cluster_id }}&amp;query={{ item.topic_name }}">{{ item.topic_name }}</a>
                        </td>

                        <td>
                            {{ item.len_delivered }} / {{ item.len_batches }}
                        </td>

                        <td>{{ item.py_object }}</td>

                        <td style="min-width:170px">
                            {% if item.last_sync %}
                                <a
                                    id="a_last_sync_{{ item.id }}"
                                    href="javascript:$.fn.zato.toggle_time('last_sync_{{ item.id }}', '{{ item.last_sync }}', '{{ item.last_sync_utc }}')">{{ item.last_sync }}
                                </a>
                            {% else %}
                                <span class='form_hint'>---</span>
                            {% endif %}
                        </td>

                        <td style="min-width:170px">
                            {% if item.last_iter_run %}
                                <a
                                    id="a_last_iter_run_{{ item.id }}"
                                    href="javascript:$.fn.zato.toggle_time('last_iter_run_{{ item.id }}', '{{ item.last_iter_run }}', '{{ item.last_iter_run_utc }}')">{{ item.last_iter_run }}
                                </a>
                            {% else %}
                                <span class='form_hint'>---</span>
                            {% endif %}
                        </td>

                        <td><!--<a href="javascript:$.fn.zato.pubsub.task.delivery-server.clear-messages('{{ item.server_name }}', '{{ item.server_pid }}', '{{ item.task_id }}')">Clear</a>--></td>
                        <td><!--<a href="javascript:$.fn.zato.pubsub.task.delivery-server.toggle-active('{{ item.server_name }}', '{{ item.server_pid }}', '{{ item.task_id }}')">{% if item.is_active %}Stop{% else %}Start{% endif %}</a>--></td>

                        <td class='ignore'>{{ item.server_name }}</td>
                        <td class='ignore'>{{ item.server_pid }}</td>

                    </tr>
                {% endfor %}
                {% else %}
                    <tr class='ignore'>
                        <td colspan='16'>No results</td>
                    </tr>
                {% endif %}

                </tbody>
            </table>
        </div>


    {% endif %} {% comment %}cluster_id{% endcomment %}

{% endif %}{% comment %}not zato_clusters{% endcomment %}

{% endblock %}
